/**
 * @author Tobias Boehm
 *
 * 16.05.2011
 */
package org.anddev.andengine.extension.tbsengine.message.client.preparematch;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.anddev.andengine.extension.tbsengine.message.ICopyable;
import org.anddev.andengine.extension.tbsengine.team.Team;

/**
 * This client message should be used to request a {@link Team} change on a 
 * specific player slot.
 * 
 * @author Tobias Boehm
 *
 */
public class ClientSlotChangeTeamReuqestMessage	extends AbsClientSlotChangeRequestMessage implements ICopyable<ClientSlotChangeTeamReuqestMessage> {

	private int mNewTeamID = -1;
	
	
	
	/* (non-Javadoc)
	 * @see org.anddev.andengine.extension.multiplayer.protocol.adt.message.IMessage#getFlag()
	 */
	@Override
	public short getFlag() {
		
		return FLAG_CLIENT_SLOT_CHANGE_TEAM_REQUEST;
	}

	@Override
	protected void onReadTransmissionClientSlotRequestData(final 
			DataInputStream pDataInputStream) throws IOException {
		
		this.mNewTeamID = pDataInputStream.readInt();
	}

	@Override
	protected void onWriteTransmissionClientSlotRequestData(final 
			DataOutputStream pDataOutputStream) throws IOException {
		
		pDataOutputStream.writeInt(this.mNewTeamID);
	}

	/**
	 * @return the mNewTeamID
	 */
	public int getNewTeamID() {
		return mNewTeamID;
	}

	/**
	 * @param mNewTeamID the mNewTeamID to set
	 */
	public void setNewTeam(final Team pNewTeam) {
		this.mNewTeamID = pNewTeam.getTeamID();
	}

	@Override
	public ClientSlotChangeTeamReuqestMessage copy() {
	
		final ClientSlotChangeTeamReuqestMessage copy = new ClientSlotChangeTeamReuqestMessage();
		
		copy.mMatchID = this.mMatchID;
		copy.mNewTeamID = this.mNewTeamID;
		copy.mPlayerID = this.mPlayerID;
		copy.mSlotID = this.mSlotID;
		
		return copy;
	}
}
